package com.wanwen.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wanwen.entity.AutoConfig;
import com.wanwen.mapper.AutoConfigMapper;
import com.wanwen.utils.Result;
import com.wanwen.utils.ResultData;

@RestController
@RequestMapping("/auto")
public class AutoConfigController {
	@Autowired
	private AutoConfigMapper autoConfigMapper;
	
	/**
	 * /users/update 开启和关闭自动分配
	 * 
	 * @param users
	 * @return rs
	 */
	@RequestMapping("/getAuto")
	public Object getAuto() {
		QueryWrapper<AutoConfig> queryWrapper = new QueryWrapper<AutoConfig>();
		AutoConfig data = autoConfigMapper.selectOne(queryWrapper);
		ResultData rs = new ResultData(0, null, data.getIsAuto().equals("开启")?true:false, null);
		return rs;
	}
	
	/**
	 * /users/update 锁定和解锁用户
	 * 
	 * @param users
	 * @return rs
	 */
	@RequestMapping("/update")
	public Object updateLock(String auto) {
		UpdateWrapper<AutoConfig> updateWrapper = new UpdateWrapper<>();
		updateWrapper.set("is_auto", auto).eq("id", 1);
		AutoConfig autoConfig = new AutoConfig(1, auto);
		int update = autoConfigMapper.update(autoConfig, updateWrapper);
		Result rs = new Result(auto+(update == 1 ? "自动分配成功" : "自动分配失败"), "", update == 1 ? true : false);
		return rs;
	}
}
